<template>
	<view>
		<!-- 查询表单 -->
		<zy-forms ref="ruleForm" :model="model" labelWidth="130" border>
			<zy-form-item :label="$t('public.materialCode')+$t('public.colon')">
				<zy-input v-model="model.materialCode" :placeholder="$t('public.pleaseInput')+$t('public.materialCode')"
					sufSlot>
					<i class="iconfont icon-saoyisao" @click="scanCode"></i>
				</zy-input>
			</zy-form-item>
			<zy-form-item :label="$t('public.materialName')+$t('public.colon')">
				<zy-input v-model="model.materialName" :placeholder="$t('public.pleaseInput')+$t('public.materialName')"
					sufSlot>
					<i class="iconfont icon-saoyisao" @click="scanName"></i>
				</zy-input>
			</zy-form-item>
			<zy-form-item :label="$t('public.position')+$t('public.colon')">
				<zy-input v-model="model.warehousePositionCode"
					:placeholder="$t('public.pleaseInput')+$t('public.position')" sufSlot>
					<i class="iconfont icon-saoyisao" @click="scanPosition"></i>
				</zy-input>
			</zy-form-item>
			<zy-form-item :label="$t('public.storage')+$t('public.colon')">
				<zy-input v-model="model.warehouseStorageCode"
					:placeholder="$t('public.pleaseInput')+$t('public.storage')" sufSlot>
					<i class="iconfont icon-saoyisao" @click="scanStorage"></i>
				</zy-input>
			</zy-form-item>
		</zy-forms>
		<!-- 底部按钮 -->
		<bottomBtn fixed :leftText="$t('public.reset')" :rightText="$t('public.search')" @rightBtn="submitBtn"
			@leftBtn="resetBtn">
		</bottomBtn>
	</view>
</template>
<script>
	import {
		queryPageMap
	} from "@/api/homepage.js"
	export default {
		data() {
			return {
				iconfont: 'iconfont icon-saoyisao',
				model: {
					materialCode: '',
					materialName: '',
					warehousePositionCode: '',
					warehouseStorageCode: '',
				},
				focus: {
					codeFocus: false,
					nameFocus: false,
					positionFocus: false,
					storageFocus: false,
				}
			}
		},
		onLoad() {
			this.getcode()
		},
		onUnload() {
			// 移除监听事件      
			uni.$off('scancodedate')
		},
		methods: {
			//主页获取箱号扫描事件
			getcode() {
				this.focus.codeFocus = true
				//PDA扫描
				var _this = this
				uni.$on('scancodedate', function(data) {
					_this.model.materialCode = data.code.replace(/\s/g, "")
				})
			},
			//二维码扫描
			scanCode() {
				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_result) {
							this.model.materialCode = ret.resp_result;
						}
					})
			},
			scanName() {
				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_result) {
							this.model.materialName = ret.resp_result;
						}
					})
			},
			scanPosition() {
				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_result) {
							this.model.warehousePositionCode = ret.resp_result;
						}
					})
			},
			scanStorage() {
				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_result) {
							this.model.warehouseStorageCode = ret.resp_result;
						}
					})
			},
			//重置
			resetBtn() {
				uni.redirectTo({
					url: "/pages/HomePage/WarehouseManage/StorageManagement/Search/index"
				})
			},
			// 查询
			submitBtn() {
				queryPageMap({
					page: 1,
					limit: 100000,
					materialCode: this.model.materialCode,
					materialName: this.model.materialName,
					materialSpec: '',
					warehousePositionCode: this.model.warehousePositionCode,
					warehouseStorageCode: this.model.warehouseStorageCode,
				}).then((res) => {
					if (res.code == 0) {
						this.$store.commit('storageInfoList', res.data)
						uni.navigateTo({
							url: './list'
						})
					} else {
						uni.showToast({
							title: res.message,
							icon: "none",
							duration: 3000
						})
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 3000
					})
				});
			},
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #ffffff;
	}
</style>